var page = 0;
var offset = 0;
var pageSize = 5;
var j=5;
function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}
var userid=getuserid(userid);

	
	function evaluatecha(){
		taiochasss();
	
		$.ajax({
			url:"http://localhost:16111/orderform/evaluatecha",
			mimeType: "post",
			dataType: "json",
			data:{
				q:0,
				j:j,
				userid:userid
			},
			xhrFields:{withCredentials: true},
			success:function(date){
				console.log(date);
				var str="";
				for(i in date){
					var time=new Date(date[i].undertime);
					var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
					
				str+="<tr class='order-item'>"+
					"<td>"+
						"<label>"+
							"<a href='udai_order_detail.html' class='num'>"+time2+"订单号:" +date[i].ordernumber +"</a>"+
							"<div class='card'>"+
								"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
								"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
								"<div class='format'>颜色：" +date[i].specifications+ "<br>尺码：" +date[i].specifications2+ "</div>"+
								"<div class='favour'>" +date[i].preferentialinformation + "</div>"+
							"</div>"+
						"</label>"+
					"</td>"+
					"<td>￥"+date[i].comityprices + "</td>"+
					"<td>"+date[i].comitynumber + "</td>"+
					"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
					"<td class='state'>"+
						"<a class='but c6'>买家已收货</a>"+
						"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
					"</td>"+
					"<td class='order'>"+
						"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
						"<a onclick='pppp(\"" + date[i].orderid + "\",\"" + date[i].spid + "\")' class='but but-primary'>" +date[i].statusbutton + "</a>"+
						// "<a href='' class='but c3'>售后</a>"+
					"</td>"+
				"</tr>";
				}
				
				document.getElementById("evaluatecha").innerHTML = str;
			},
		});
	}
	
	
		function taiochasss(){
			$.ajax({
			url: "http://localhost:16111/orderform/taiochass",
			mimeType: "post",
			dataType: "json",
			data:{
				userid:userid,
			},
			xhrFields:{withCredentials: true},
			success: function(date){
				document.getElementById("articless").innerHTML = date;
			},
			});
		}
		
		//分页
		function sans(){
			if(offset-pageSize<0){
						alert("没有上一页");
						return;
					}else{
						offset=offset-pageSize;
						page=page+1;
					} 
			var str="";
			$.ajax({
				url: "http://localhost:16111/orderform/evaluatecha",
				mimeType: "post",
				dataType: "json",
				data:{
					q:offset,
					j:j,
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success:function(date){
					var str="";
					console.log(date);
					for(i in date){
						var time=new Date(date[i].undertime);
							var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
						str+="<tr class='order-item'>"+
							"<td>"+
								"<label>"+
									"<a href='udai_order_detail.html' class='num'>"+time2+"订单号:" +date[i].ordernumber +"</a>"+
									"<div class='card'>"+
										"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
										"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
										"<div class='format'>颜色：" +date[i].specifications+ "<br>尺码：" +date[i].specifications2+ "</div>"+
										"<div class='favour'>" +date[i].preferentialinformation + "</div>"+
									"</div>"+
								"</label>"+
							"</td>"+
							"<td>￥"+date[i].comityprices + "</td>"+
							"<td>"+date[i].comitynumber + "</td>"+
							"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
							"<td class='state'>"+
								"<a class='but c6'>买家已收货</a>"+
								"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
							"</td>"+
							"<td class='order'>"+
								"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
								"<a onclick='pppp(\"" + date[i].orderid + "\",\"" + date[i].spid + "\")' class='but but-primary'>" +date[i].statusbutton + "</a>"+
								
							"</td>"+
						"</tr>";
					}
					document.getElementById("paymentcha").innerHTML = str;
				},
				
			})
		}
		
		
		function xiaos(){
			if(page==2){
				alert("没有下一页");
				return;
				}else{
				offset=offset+pageSize;
				page=page-1;
						} 
			
			$.ajax({
				url: "http://localhost:16111/orderform/evaluatecha",
				mimeType: "post",
				dataType: "json",
				data:{
					q:offset,
					j:j,
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success:function(date){
					
					var str="";
					for(i in date){
						var time=new Date(date[i].undertime);
							var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
						str+="<tr class='order-item'>"+
							"<td>"+
								"<label>"+
									"<a href='udai_order_detail.html' class='num'>"+time2+"订单号:" +date[i].ordernumber +"</a>"+
									"<div class='card'>"+
										"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
										"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
										"<div class='format'>颜色：" +date[i].specifications+ "<br>尺码：" +date[i].specifications2+ "</div>"+
										"<div class='favour'>" +date[i].preferentialinformation + "</div>"+
									"</div>"+
								"</label>"+
							"</td>"+
							"<td>￥"+date[i].comityprices + "</td>"+
							"<td>"+date[i].comitynumber + "</td>"+
							"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
							"<td class='state'>"+
								"<a class='but c6'>买家已收货</a>"+
								"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
							"</td>"+
							"<td class='order'>"+
								"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
								"<a onclick='pppp(\"" + date[i].orderid + "\",\"" + date[i].spid + "\")' class='but but-primary'>" +date[i].statusbutton + "</a>"+
								
							"</td>"+
						"</tr>";
					}
					document.getElementById("paymentcha").innerHTML = str;
				},
				
			})
		}
		
		
		function pppp(orderid,spid){
			
				localStorage.setItem("orderid",orderid);
				
				localStorage.setItem("spid",spid);
				location.href='order_evaluate.html';
			}